package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.OrderList;
import cn.wolfcode.trip.base.domain.Packsack;
import cn.wolfcode.trip.base.mapper.OrderListMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IIntegralService;
import cn.wolfcode.trip.base.service.IOrderListService;
import cn.wolfcode.trip.base.service.IPacksackService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class OrderListServiceImpl implements IOrderListService {
    @Autowired
    private OrderListMapper orderListMapper;
    @Autowired
    private IIntegralService integralService;
    @Autowired
    private IPacksackService packsackService;
    @Override
    public PageInfo query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<OrderList> orderLists = orderListMapper.selectForList(qo);
        return new PageInfo(orderLists);
    }

    @Override
    public void save(OrderList orderList) {
        orderList.setCreationtime(new Date());
        orderListMapper.insert(orderList);
        //同步扣积分
        integralService.shop(orderList);
        //关联用户物品;
        Packsack object = Packsack.getObject(orderList);
        packsackService.save(object);
    }
}
